import React from 'react';
import { Modal } from 'antd';
import Api from 'Utils/api';
import '../index.scss';

export default class RecordModal extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      record: {},
      visible: false,
      confirmLoading: false,
      carriage: false,
      newRecord: ''
    };
  }
  handleOk() {
    const { record, carriage } = this.state;
    this.setState({
      visible: false,
      confirmLoading: false
    });
    const api = new Api({
      method: 'PATCH',
      path: `/processes/admin/handle/${record.id}`,
      query: {
        is_released: !carriage,
      },
      success: () => {
        this.props.onEdit();
      }
    });
    api.run();
  }

  onCancel() {
    this.setState({
      visible: false, confirmLoading: false
    });
  }

  show(record) {
    this.setState({
      visible: true,
      record: record,
      carriage: record.is_released
    });
  }

  render() {
    return (
      <Modal
        className="choose-record-modal small-modal"
        title={this.props.title}
        visible={this.state.visible}
        confirmLoading={this.state.confirmLoading}
        onCancel={this.onCancel.bind(this)}
        onOk={this.handleOk.bind(this)}
        width={800}
      >
        <span >{this.props.message}</span >
      </Modal >
    );
  }
}
